package com.longrise.bjjt.ui;

import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

import com.longrise.bjjt_lib.R;

/**
 * Created by admin on 2016-5-10.
 */
public class ChosePictureDialog extends Dialog implements View.OnClickListener {
    private Button changetakephoto;
    private Button changefrom_album;
    private Button changenagative;
    private View view;

    public ChosePictureDialog(Context context) {
        super(context);
        init();
        initClickListener();
    }


    public ChosePictureDialog(Context context, int theme) {
        super(context, theme);
        init();
        initClickListener();
    }

    public ChosePictureDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        init();
        initClickListener();
    }

    private void init() {


        view = View.inflate(getContext(), R.layout.change_headportrait2, null);
        this.setContentView(view);
        WindowManager windowManager = (WindowManager) getContext()
                .getSystemService(Context.WINDOW_SERVICE);
        Display display = windowManager.getDefaultDisplay();

        Window dialogWindow = this.getWindow();
//        dialogWindow.setGravity(Gravity.BOTTOM);
        WindowManager.LayoutParams p = this.getWindow().getAttributes();
        p.height = (int) (display.getHeight() * 0.4);
        p.width = (int) (display.getWidth() * 0.8);
        dialogWindow.setAttributes(p);
        // 设置显示位置
        this.show();

    }

    private void initClickListener() {
        changetakephoto = (Button) view.findViewById(R.id.changetakephoto);
        changefrom_album = (Button) view.findViewById(R.id.changefrom_album);
        changenagative = (Button) view.findViewById(R.id.changenagative);
        changetakephoto.setOnClickListener(this);
        changefrom_album.setOnClickListener(this);
        changenagative.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.changetakephoto) {

            mChoseItemInterface.chosephoto();
        }
        if (view.getId() == R.id.changefrom_album) {
            mChoseItemInterface.chosealbum();
        }
        if (view.getId() == R.id.changenagative) {
            this.dismiss();
        }
    }


    public interface ChoseItemInterface {
        void chosephoto();

        void chosealbum();
    }

    public ChoseItemInterface mChoseItemInterface;

    public void setmChoseItemInterface(ChoseItemInterface mChoseItemInterface) {
        this.mChoseItemInterface = mChoseItemInterface;
    }
}
